package star.crust.cartspace.framework;

import star.core.util.geometry.DoubleXYZ;
import star.core.util.geometry.POTransform;

/**
 * Classe che rappresenta il piano di partizionamento
 * della gerarchia
 */
public class CrtAabbPlane {

	private double[] norm= new double[3]; //vettore normale al piano
	private double dist; //area del piano

	public CrtAabbPlane(){}

	public CrtAabbPlane(CrtAabbPlane p, POTransform t)
	{
		this.norm = t.operator(p.norm);
		this.dist = p.dist + t.getPosition().dot(this.norm); 	
	}
	public void setValue(double a, double b, double c, double d)
	{
		norm[0]=a; norm[1]=b; norm[2]=c;
		dist = d;
	}

	public void setValue(double[] vector, DoubleXYZ point)
	{
		this.norm=CrtAabbUtil.divNormal(vector);
		this.dist=point.dot(this.norm);
	}

	public double operator(DoubleXYZ p)
	{
		return p.dot(this.norm) - dist;
	}

	public double getDist()
	{
		return this.dist;
	}

	public double[] getNorm()
	{
		return this.norm;
	}

	public String toString()
	{
		return norm[0] +" "+ norm[1] + " " + norm[2];
	}

}
